#@adminLayout()

#define main()

<link rel="stylesheet" href="/assets/editor_md/css/editormd.css"/>
<div class="jfa-header-box" id="jfa-header-box">
    <div class="jfa-crumbs" id="jfa-crumbs">
        内容管理 / <a href="/admin/blog">博客管理</a> / #(blog.id?? == null ? '创建' : '修改')
    </div>
    <div class="jfa-search-box"></div>
    #include("/view/_admin/common/_header_right.html")
</div>

### 内容区域
<div class="jfa-content-box" id="jfa-content-box">
    <div class="jfa-content" id="jfa-content">

        <form class="form-horizontal margin-top-30" id="myArticleForm"
              action="#(blog.id?? == null ? '/admin/blog/save' : '/admin/blog/update')"
              method="post">
            <input type="hidden" name="blog.id" value="#(blog.id??)"/>
            <div class="form-group">
                <label class="col-sm-2 control-label">标题</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"
                           placeholder="请输入标题" name="blog.title" value="#(blog.title??)">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">分类</label>
                <div class="col-sm-8">
                    <select name="blog.category" class="form-control">
                        <option value="">请选择</option>
                        #for(x:categoryList)
                        #if(x.name == blog.category??)
                        <option value="#(x.name)" selected>#(x.name)</option>
                        #else
                        <option value="#(x.name)">#(x.name)</option>
                        #end
                        #end
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">标签</label>
                <div class="col-sm-8">
                    <select name="blog.tag_id" class="form-control">
                        <option value="">请选择</option>
                        #for(x:tagList)
                        #if(x.id == blog.tag_id??)
                        <option value="#(x.id)" selected>#(x.name)</option>
                        #else
                        <option value="#(x.id)">#(x.name)</option>
                        #end
                        #end
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">正文</label>
                <div class="col-sm-5" id="md" style="min-height: 500px;">
                    <textarea name="blog.markedContent" style="display:none;">#(blog.markedContent??) </textarea>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-8">
                    <input class="btn btn-primary" type="submit" value="提交"/>
                </div>
            </div>
        </form>

    </div><!-- END OF jfa-content -->
</div><!-- END OF jfa-content-box -->
<style type="text/css">
    #myArticleForm {
        width: 1200px;
        text-align: left;
    }

    .form-group {
        margin-bottom: 25px;

    }

    .jfa-content label {
        line-height: 1;
        vertical-align: baseline;
        color: #23527c;
        font-size: 20px;
        font-weight: normal;
        margin-bottom: 8px;;
    }
</style>
<script src="/assets/editor_md/editormd.js"></script>
<script type="text/javascript">

    var content = $("textarea[name = 'blog.markedContent']").text();
    if (content == undefined || content == null || content == "")
        content = null;

    $(document).ready(function () {


        editormd("md", {
            width: "80%",
            markdown: content,
            path: '/assets/editor_md/lib/',
            toolbarIcons: function () {
                return ["undo", "redo", "|", "bold", "hr", "|", "h1", "h2", "h3", "h4", "h5", "h6", "italic",
                    "quote", "uppercase", "list-ul", "list-ol", "hr", "image", "code", "code-block",
                    "table", "datetime", "html-entities", "pagebreak", "search", "image",
                    "||", "watch", "preview"]
            },
            tex: true,                   // 开启科学公式TeX语言支持，默认关闭
            flowChart: true,             // 开启流程图支持，默认关闭
            sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
            saveHTMLToTextarea: true,
            imageUpload: true,
            imageFormats: ["jpg", "jpeg", "gif", "png", "bmp"],
            imageUploadURL: "",
            crossDomainUpload: true,
            uploadCallbackURL: "",
            autoHeight: true
        });

        $("#myArticleForm").ajaxForm({
            dataType: "json"
            , beforeSubmit: function (formData, jqForm, options) {
            }
            , success: function (ret) {
                if (ret.state == "ok") {
                    location.href = "/admin/blog?p=#(p ?? 1)";
                } else {
                    showFailMsg(ret.msg);
                }
            }
            , error: function (ret) {
                alert(ret.statusText);
            }
            , complete: function (ret) {
            } 	      // 无论是 success 还是 error，最终都会被回调
        });
    });
</script>

#end
